
# Mel Ó Cinnéide, Jan 2013
# with thanks to Freeman&co. for the example
          require "forwardable"
class Decaf
  def description
    "decaffinated coffee"
  end
  def cost
    2.0
  end
end

class Expresso
  def description
    "expresso coffee"
  end
  def cost
    1.5
  end
end

class CoffeeDecorator
  extend Forwardable
  def_delegators :@coffee, :description, :cost
  def initialize coffee
      @coffee = coffee
  end

end

class Milk < CoffeeDecorator

  def initialize coffee
    super (coffee)
  end

  def description
    puts "fresh milk"
    result = super + " " + "milk"
    puts "no milk"
    return result
  end
  def cost
    super + 0.50
  end
end

class Sugar  < CoffeeDecorator
  def initialize coffee
    super (coffee)
  end

  def description
    super  + " " + "sugar"
  end
  def cost
    super + 0.20
  end
end

=begin
#class DecafWithMilkAndSugar
#  def initialize
#    @coffee = Decaf.new
#    @milk = Milk.new
#    @sugar = Sugar.new
#  end
#  def description
#    "#{@coffee.description} #{@milk.description} #{@sugar.description}"
#  end
#  def cost
#    @coffee.cost + @milk.cost + @sugar.cost
#  end
#end
=end

my_coffee= Sugar.new(Milk.new (Decaf.new)    )
#my_coffee = DecafWithMilkAndSugar.new
puts "My coffee is:"
puts my_coffee.description
puts "and costs:"
puts my_coffee.cost


